#include "Accpetor.hpp"
#include "EventLoop.hpp"
#include <iostream>
#include <sys/epoll.h>
#include <unistd.h>
using std::cout;
using std::endl;

void onConnection(wd::TcpConnectionptr tcpconn){
    printf("a new clienfd connected.\n");
}

void onMessage(wd::TcpConnectionptr tcpconn){
    string msg = tcpconn->receive();
    cout << "receive msg:"<< msg << endl;

    tcpconn->send("receive your msg !");
}

void onClose(wd::TcpConnectionptr tcpconn){
    printf("a new clienfd closed.\n");
}

int main()
{
    wd::Acceptor acceptor(12345,"0.0.0.0");
    acceptor.ready();

    wd::EventLoop eventloop(acceptor);
    
    eventloop.setAllCallbacks(onConnection,onMessage,onClose);
    eventloop.loop();
    

    sleep(60);
    eventloop.unloop();

    return 0;
}

